/**
 * ***************************************************************************
 * Copyright (C) 1999 California Institute of Technology. All rights reserved US
 * Government Sponsorship under NASA contract NAS7-918 is acknowledged
 * **************************************************************************
 */
package util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
 * This is utility class implements a hashing methods used to provide one way
 * encryption of user password.
 *
 * @author Joe Chavez
 * @version $Id: PasswordHash.java,v 1.3 2009/01/27 19:11:19 tatianag Exp $
 */
public class PasswordHash {


    public static String MD5Password(String str) throws NoSuchAlgorithmException {


        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(str.getBytes());

        byte byteData[] = md.digest();

        StringBuffer hexString = new StringBuffer();
        for (int i=0;i<byteData.length;i++) {
            String hex=Integer.toHexString(0xff & byteData[i]);
            if(hex.length()==1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
}
